<!--#include file="conn.asp"-->
<!--#include file="chkuser.asp"-->
<!--#include file="upload_5xsoft.asp"-->
<!--#include file="upload_AnUpload.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>body,td,p,div{ margin:0; font-size:12px; color:#FF0000}</style>
</head>
<body>
<%
dim n,x,SavePath,strFileName,strFileType,FileName,strJS
if MaxUpFileSize_con<=0 then
	response.Write "请先配置允许上传文件的大小！"
	response.End()
end if
if UpFileType_con="" then
	response.Write "请先配置允许上传文件的类型！"
	response.End()
end if
n=request("n")
x=request("x")
if n="" then
	response.Write("未指向上传目标，参数：n")
	response.End()
end if
if x="" then
	response.Write("未指定上传方式，参数：x")
	response.End()
end if

SavePath = UploadSavePath_con    '存放上传文件的目录
if right(SavePath,1)<>"/" then SavePath = SavePath & "/"

if EnableUploadFile_con<>True then
	response.write "系统未开放文件上传功能"
else
	if session("SYSUser")="" then
		response.Write("请登录后再使用本功能！")
	else
		select case UploadApp_con
			case 0
				response.Write("Error：系统参数配置没有选择应用组件...")
				response.End()
			case 1
				call upload_1()  '使用化境无组件上传类
			case 2
				call upload_2()  '使用艾恩无组件上传类
			case 3
				call upload_3()  '使用AspUpload组件上传
		end select
		if instr(lcase(n),"watermark")<=0 then  '防止Admin_Setting.asp中水印logo自加水印
			if Watermark_con=True then call ImgWatermark()
		end if
		select case x
			case 1
				strJS="<script language='javascript'>"
				strJS=strJS&"parent.document.getElementById('"&n&"').value='"&replace(FileName,"./../","")&"';"
				strJS=strJS&"</script>"
				strJS=strJS&"<input value='"&replace(FileName,"./../","")&"' name='text' type='hidden'>"
				strJS=strJS&"上传成功<a href='#' onclick="&chr(34)&"window.clipboardData.setData('text',text.value);alert('复制成功');"&chr(34)&">[复制地址]</a>&nbsp;<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>[重新上传]</a>"
			case 2
				strJS="<SCRIPT language='javascript'>" & vbcrlf
				msg="上传文件成功！"
				HTMLtext=""
				select case strFileType
					case ".jpg",".gif",".png",".bmp"
						HTMLtext="<img kesrc="& FileName &" src=" & FileName & " border=0 GALLERYIMG=no>" 
					case ".swf"
						HTMLtext="<embed src=" & FileName & " type=application/x-shockwave-flash "
						if ImgWidth>0 then
							HTMLtext=HTMLtext & " width=" & ImgWidth
						end if
						if ImgHeight>0 then
							HTMLtext=HTMLtext & " height=" & ImgHeight
						end if
						HTMLtext=HTMLtext & " quality=high />"
					case else
						HTMLtext="<a href=" & FileName & " kesrc="& FileName &" target=_blank>[附件: Download]</a>"
				end select
	
				strJS=strJS & " parent.KE.util.focus('"&n&"');" & vbcrlf 
				strJS=strJS & " parent.KE.util.selection('"&n&"');" & vbcrlf 
				strJS=strJS & " parent.KE.util.insertHtml('"&n&"', '"&HTMLtext&"');" & vbcrlf 
				
				strJS=strJS & "parent.AddItem('" & replace(replace(FileName,"../",""),"./","") & "');" & vbcrlf
				strJS=strJS & "alert('" & msg & "');" & vbcrlf
				strJS=strJS & "location='Upload_form_lt.asp?n="&n&"&x="&x&"';" & vbcrlf
				strJS=strJS & "</script>"
		end select
		response.write strJS
	end if
end if
%>
</body>
</html>
<%
'使用化境无组件上传类
sub upload_1()
	dim upload
	set upload=new upload_5xsoft
	set file=upload.file("FileName")
	if file.fileSize>0 then
		strFileType = lcase(mid(file.filename,instrrev(file.filename,".")))  
		if checkFileType(strFileType)=false then
			response.write "Error：文件格式不正确！ [<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]"
			response.end
		elseif file.fileSize>MaxUpFileSize_con*1024 then
			response.Write("Error：只能上传大小 " & CStr(MaxUpFileSize_con) & "kb 以内的文件！ [<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]")
			response.end
		else
			call CreateStrFileName()
		    FileName = SavePath & strFileName & strFileType
			file.saveAs Server.mappath(FileName)
		end if
	else
		response.Write "请先选择你要上传的文件！ [<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]"
	end if
	set file=nothing
	set upload=nothing
end sub

'使用艾恩无组件上传类
sub upload_2()
	dim upload
	set upload = new AnUpLoad
	upload.Exe = UpFileType_con
	upload.MaxSize = MaxUpFileSize_con * 1024 'KB*1024Byte
	upload.GetData()
	if upload.ErrorID>0 then 
		response.Write upload.Description
		response.End()
	else
		for each f in upload.files(-1)
			dim file
			set file = upload.files(f)
			if not(file is nothing) then
				call CreateStrFileName()
				file.UserSetName=strFileName
				set result = file.saveToFile(SavePath,-1,true)
				if not result.error then
					'response.Write "文件'" & file.LocalName & "'上传成功，保存位置'" & server.MapPath(savepath & "/" & file.filename) & "',文件大小" & file.size & "字节<br />"
					FileName=SavePath & file.filename
					strFileType = lcase(mid(FileName,instrrev(FileName,".")))  
				else
					response.Write file.Exception
					response.End()
				end if
			end if
			set file = nothing
		next
	end if
	set upload = nothing
end sub

'使用AspUpload组件上传
sub upload_3()
	if not IsObjInstalled("Persits.Upload.1") then
		response.Write "Error:对不起，该服务器不支持AspUpload组件！ [<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]"
		response.End()
	end if
	dim upload,FileCount
	call CreateStrFileName()
	Set upload = Server.CreateObject("Persits.Upload.1")
	upload.CodePage = 65001
	upload.SetMaxSize MaxUpFileSize_con * 1024, True
	upload.IgnoreNoPost = True
	On Error Resume Next
	FileCount = upload.Save
	if FileCount<1 then
		response.Write "请先选择你要上传的文件！ [<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]"
		response.End()
	end if
	If Err.Number = 8 Then
		response.Write("Error：只能上传大小 " & CStr(MaxUpFileSize_con) & "kb 以内的文件！ [<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]")
		response.End()
	end if
	If Err <> 0 Then
		Response.Write "AspUpload: An error occurred: " & Err.Description
		response.End()
	End If
	For Each File in upload.Files
		strFileType=File.Ext
		if checkFileType(strFileType)=false then
			response.write "Error：文件格式不正确！　[<a href='Upload_form_lt.asp?n="&n&"&x="&x&"'>返回</a>]"
			response.End()
		else
		    FileName = SavePath & strFileName & strFileType
			File.SaveAs server.MapPath(FileName)
		end if
	Next
end sub

sub CreateStrFileName()
	if CreateDateFloder_con=True then
		SavePath = SavePath & year(now) & month(now) & day(now) & "/"
		call NewFolder(SavePath)
	end if
	randomize
	ranNum=int(900*rnd)+100
	strFileName=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
end sub

function checkFileType(ByVal strFileType)
	dim fileTypePass:fileTypePass=false
	arrUpFileType=split(UpFileType_con,"|")
	for i=0 to ubound(arrUpFileType)
		if strFileType="."&trim(arrUpFileType(i)) then
			fileTypePass=true
			exit for
		end if
	next
	checkFileType=fileTypePass
end function


sub ImgWatermark()
	Set Jpeg = Server.CreateObject("Persits.Jpeg")  
	Jpeg.Open Server.MapPath(FileName)  
	
	if ThumbImage_con=True then  '图片缩略图
		if ThumbImageMaxWidth_con>0 or ThumbImageMaxHeight_con>0 then
			W=ThumbImageMaxWidth_con
			H=ThumbImageMaxHeight_con
			
			if(Jpeg.OriginalWidth/Jpeg.OriginalHeight>=W/H) then
				if Jpeg.OriginalWidth>W then
					Jpeg.Width=W
					Jpeg.Height=Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
				end if
			else
				if Jpeg.OriginalHeight>H then
					Jpeg.Height=H
					Jpeg.Width=Jpeg.OriginalWidth * H / Jpeg.OriginalHeight
				end if
			end if
			
			If Jpeg.OriginalWidth > W Then
			   Jpeg.Width = W
			   Jpeg.Height = Jpeg.OriginalHeight * W / Jpeg.OriginalWidth
			End If
			If Jpeg.OriginalHeight > H Then
			   Jpeg.Height = H
			   Jpeg.Width = Jpeg.OriginalWidth * H / Jpeg.OriginalHeight
			End If
		end if
	end if
	
	if WatermarkAddBd_con=True then  '以下是对图片进行边框处理
	    if WatermarkBdColor_con<>"" and  WatermarkBdWidth_con>0 then
			Jpeg.Canvas.Pen.Color = "&H"&replace(WatermarkBdColor_con,"#","") '颜色
			Jpeg.Canvas.Pen.Width = WatermarkBdWidth_con '画笔宽度  
			Jpeg.Canvas.Brush.Solid = False '是否加粗处理  
			Jpeg.Canvas.Bar 1, 1, Jpeg.Width, Jpeg.Height '起始X坐标 起始Y坐标 输入长度 输入高度
		end if
	end if  
	
	
	select case WatermarkType_con
	case 1
		select case WatermarkLocal_con
			case 0,1
				LocalX=WatermarkPadingX_con
				LocalY=WatermarkPadingY_con
			case 2
				LocalX=WatermarkPadingX_con
				LocalY=Jpeg.Height-WatermarkPadingY_con
			case 3
				LocalX=Jpeg.Width-WatermarkPadingX_con
				LocalY=WatermarkPadingY_con
			case 4
				LocalX=Jpeg.Width-WatermarkPadingX_con
				LocalY=Jpeg.Height-WatermarkPadingY_con
			case 5
				LocalX=cint((Jpeg.Width-WatermarkPadingX_con)/2)
				LocalY=cint((Jpeg.Height-WatermarkPadingY_con)/2)
		end select
	case 2
		select case x
			case 1
				if WatermarkPic_con<>"" then 
					Set LogoImgx = Server.CreateObject("Persits.Jpeg")
					LogoImgx.Open Server.MapPath("./../"&WatermarkPic_con)
					LogoImgxWidth=LogoImgx.OriginalWidth
					LogoImgxHeight=LogoImgx.OriginalHeight
				end if
			case 2
				if WatermarkBigPic_con<>"" then
					Set LogoImgx = Server.CreateObject("Persits.Jpeg")
					LogoImgx.Open Server.MapPath("./../"&WatermarkBigPic_con)
					LogoImgxWidth=LogoImgx.OriginalWidth
					LogoImgxHeight=LogoImgx.OriginalHeight
				end if
		end select
		select case WatermarkLocal_con
			case 0,1
				LocalX=WatermarkPadingX_con
				LocalY=WatermarkPadingY_con
			case 2
				LocalX=WatermarkPadingX_con
				LocalY=Jpeg.Height-WatermarkPadingY_con-LogoImgxHeight
			case 3
				LocalX=Jpeg.Width-WatermarkPadingX_con-LogoImgxWidth
				LocalY=WatermarkPadingY_con
			case 4
				LocalX=Jpeg.Width-WatermarkPadingX_con-LogoImgxWidth
				LocalY=Jpeg.Height-WatermarkPadingY_con-LogoImgxHeight
			case 5
				LocalX=cint((Jpeg.Width-WatermarkPadingX_con-LogoImgxWidth)/2)
				LocalY=cint((Jpeg.Height-WatermarkPadingY_con-LogoImgxHeight)/2)
		end select
	end select
	
	select case WatermarkType_con
		case 1
			Text = WatermarkText_con
			if WatermarkTextFontSize_con>0 then Jpeg.Canvas.Font.Size = WatermarkTextFontSize_con
			if WatermarkTextColor_con<>"" then Jpeg.Canvas.Font.Color = "&H"&replace(WatermarkTextColor_con,"#","")
			if WatermarkTextOpacity_con<>"" then Jpeg.Canvas.Font.Opacity = WatermarkTextOpacity_con
			if WatermarkTextFontFamily_con="" then
				fontfamily="c:\Windows\Fonts\Arial.ttf"
			else
				if mid(WatermarkTextFontFamily_con,2,2)=":\" then
					fontfamily=WatermarkTextFontFamily_con
				else
					fontfamily=server.MapPath(WatermarkTextFontFamily_con)
				end if
			end if
			Jpeg.Canvas.PrintTextEx Text, LocalX, LocalY, fontfamily
		case 2
			select case x
				case 1
					if WatermarkPic_con<>"" then 
						if lcase(right(WatermarkPic_con,4))<>".png" then
							Set LogoImg = Server.CreateObject("Persits.Jpeg")
							LogoImg.Open Server.MapPath("./../"&WatermarkPic_con) 
							Jpeg.Canvas.DrawImage LocalX, LocalY, LogoImg
						else
							Jpeg.Canvas.DrawPNG LocalX, LocalY,  Server.MapPath("./../"&WatermarkPic_con)
						end if
					end if
				case 2
					if WatermarkBigPic_con<>"" then
						if lcase(right(WatermarkBigPic_con,4))<>".png" then
							Set LogoImg = Server.CreateObject("Persits.Jpeg")
							LogoImg.Open Server.MapPath("./../"&WatermarkBigPic_con) 
							Jpeg.Canvas.DrawImage LocalX, LocalY, LogoImg
						else
							Jpeg.Canvas.DrawPNG LocalX, LocalY,  Server.MapPath("./../"&WatermarkBigPic_con)
						end if
					end if
			end select
	end select
	Jpeg.Save Server.MapPath(FileName) '保存  
end sub
%>

